<template>
    <div class="wrapper">
        <swiper :options="swiperOption" v-if="showSwiper">
            <!-- slides -->
            <swiper-slide v-for="item of list" :key="item.id">
                <img
                    class="swiper-img"
                    :src="item.imgUrl"
                    >
            </swiper-slide>
            <!-- Optional controls -->
            <div class="swiper-pagination" slot="pagination"></div>
            <div class="swiper-pagination" slot="pagination"></div>
            <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default{
    name: 'HomeSwiper',
    props: {
        list: Array
    },
    data () {
        return {
            swiperOption: {
                pagination: '.swiper-pagination',
                // 设置循环插件支持循环轮播
                loop: true
            }
        }
    },
    computed: {
        showSwiper () {
            return this.list.length
        }
    }
}

</script>

<style lang="stylus" scoped>
    //效果穿透,wrapper下的所有指定class不受scoped限制
    .wrapper >>> .swiper-pagination-bullet-active
        background: #eff0f17a
    .swiper-img
        width: 100%
    .wrapper
        // 实现宽高按图片比例设置固定值,标准写法
        overflow: hidden
        width: 100%
        height: 0
        padding-bottom: 30%
</style>
